package com.maple.retry.retrytask;

import com.maple.retry.retrytask.manager.RetryTaskManager;
import com.maple.retry.retrytask.manager.RetryTaskManagerImpl;
import com.maple.retry.retrytask.model.RetryTaskInfo;

import java.util.concurrent.Callable;

/**
 * @author: maple
 * @version: RetryTaskRunner.java, v 0.1 2020年12月29日 12:01 maple Exp $
 */
public class RetryTaskRunner implements Callable<RetryTaskResult> {

    /**
     * 配置执行器
     */
    private RetryTaskExecutor executor;

    /**
     * 结果决策
     */
    private ScheduleStrategy policyVoter;

    /**
     * 补偿任务
     */
    private RetryTaskInfo taskInfo;

    /**
     * 补偿任务执行器
     */
    private RetryTaskManager retryTaskManager;

    public RetryTaskRunner(RetryTaskInfo taskInfo, RetryTaskExecutor executor, RetryTaskManager retryTaskManager, ScheduleStrategy policyVoter) {
        this.taskInfo = taskInfo;
        this.executor = executor;
        this.retryTaskManager = retryTaskManager;
        this.policyVoter = policyVoter;
    }

    @Override
    public RetryTaskResult call() throws Exception {
        return ((RetryTaskManagerImpl) retryTaskManager).innerProcess(taskInfo, executor, policyVoter);
    }
}
